package com.java.prttern.notes;

import com.java.prttern.Facotry.Rectangle;
import com.java.prttern.Facotry.Shape;
import com.java.prttern.Facotry.Square;

public class ShapeFactory1 {
    //省略类型强制转换，支持多态
    public static < T> T getClass(Class<?extends T> clazz){
        T obj=null;
        try {
            obj = (T) Class.forName(clazz.getName()).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return obj;
    }

    public static void main(String[] args) {
        Rectangle rect=ShapeFactory1.getClass(Rectangle.class);
        rect.draw();
        Shape square=ShapeFactory1.getClass(Square.class);
        square.draw();
    }
}
